
count  //this is the full sample, 899 

preserve
keep if el_T_Cmp_subject_teach_Ma==1 
count
keep school_id 
duplicates drop 
count 
restore 


****************CLEAN DATA***************
***mastering the student curriculum if he or she marked 80% or more of the spelling and grammar questions correct

***Minimum knowledge in language as marking 80% of one part test correctly 


**This has too many missing values to really be useful 
gen teacher_effectiveness=.
gen teacher_absent_days = . 
forvalues i=1(1)11 { 
replace teacher_effectiveness=bl_HT_e06_effectiveness_`i' if bl_HT_e01_teacher_id_`i'==teacher_id  

replace teacher_absent_days = bl_HT_e05_absent_days_`i' if bl_HT_e01_teacher_id_`i'==teacher_id
} 

tab teacher_effectiveness, sum(el_T_Cmp_Eg_pct_scored)
tab teacher_effectiveness, sum(el_T_Cmp_Ma_pct_scored)

***Demographics
gen male =bl_T_c06_gender_female==0 if mi_bl_T_c06_gender_female==0
	
gen age = bl_T_c07_age  if mi_bl_T_c07_age==0
   
gen age_sq=age^2
	
gen educ_voc_lower=bl_T_c09_highest_education<=7  if !mi(bl_T_c09_highest_education) 
	replace educ_voc_lower=1 if mv_T_c05_highest_edu<=7 & educ_voc_lower==. & !mi(mv_T_c05_highest_edu)
	replace educ_voc_lower=0 if mv_T_c05_highest_edu>=8 & educ_voc_lower==. & !mi(mv_T_c05_highest_edu)
	replace educ_voc_lower=1 if el_T_c07_highest_education<=7 & educ_voc_lower==. & !mi(el_T_c07_highest_education)
	replace educ_voc_lower=0 if el_T_c07_highest_education>=8 & educ_voc_lower==. & !mi(el_T_c07_highest_education)

gen educ_bach=bl_T_c09_highest_education==8  if !mi(bl_T_c09_highest_education) 
	
	replace educ_bach=1 if mv_T_c05_highest_edu==8 & educ_bach==. & !mi(mv_T_c05_highest_edu)
	replace educ_bach=0 if mv_T_c05_highest_edu>8 & educ_bach==. & !mi(mv_T_c05_highest_edu)
	replace educ_bach=0 if mv_T_c05_highest_edu<8 & educ_bach==. & !mi(mv_T_c05_highest_edu)
	replace educ_bach=1 if el_T_c07_highest_education==8 & educ_bach==. & !mi(el_T_c07_highest_education)
	replace educ_bach=0 if el_T_c07_highest_education>8 & educ_bach==. & !mi(el_T_c07_highest_education)
	replace educ_bach=0 if el_T_c07_highest_education<8 & educ_bach==. & !mi(el_T_c07_highest_education)

***Small samples so combining bachelors and vocation 
gen educ_bach_lower=1 if educ_bach==1 | educ_voc_lower==1
replace educ_bach_lower=0 if educ_bach==0 & educ_voc_lower==0
	
gen educ_masters_higher=bl_T_c09_highest_education>=9 if !mi(bl_T_c09_highest_education) 

	replace educ_masters_higher=1 if mv_T_c05_highest_edu>=9 & educ_masters_higher==. & !mi(mv_T_c05_highest_edu)
	replace educ_masters_higher=0 if mv_T_c05_highest_edu<9 & educ_masters_higher==. & !mi(mv_T_c05_highest_edu)
	replace educ_masters_higher=1 if el_T_c07_highest_education>=9 & educ_masters_higher==. & !mi(el_T_c07_highest_education)
	replace educ_masters_higher=0 if el_T_c07_highest_education<9 & educ_masters_higher==. & !mi(el_T_c07_highest_education)
sum educ_*

gen years_experience =  bl_T_c12_experience_years if mi_bl_T_c12_experience_years==0
 
	 
gen years_experience_sq=years_experience^2
	
gen years_this_school= bl_T_c13_teaching_years_school
	replace years_this_school = mv_T_c07_teacher_this_school if years_this_school==. & !mi(mv_T_c07_teacher_this_school)
	replace years_this_school =el_T_c11_years_teaching_school  if years_this_school==.  & !mi(el_T_c11_years_teaching_school)

foreach var of varlist male age age_sq educ_voc_lower educ_bach* educ_masters_higher years_experience years_experience_sq years_this_school { 
	gen `var'_imp_flag=( `var' == . )
	gen `var'_imp=`var'
	sum `var'_imp
	replace `var'_imp=r(mean) if `var'_imp_flag==1
}
	
	
***Baseline variables: These have funny sample sizes (looks like they are missing "no") 
sum bl_T_c30_access_textbook_maths bl_T_c31_access_textbook_english bl_HT_effective_assessed

*This variable looks like it's missing "yes": ask  
sum  bl_T_a15_guest_teacher 

***Few work at other schools: not considering
gen bl_work_other_school=1 if bl_T_c15_work_other_school==1
	replace bl_work_other_school=0 if bl_T_c15_work_other_school==2
 
**BL gender variables: coded so that 1 supports gender equality
gen bl_T_boys_get_opp=(bl_T_c34_boys_get_opportunities>=4)
replace bl_T_boys_get_opp=. if bl_T_c34_boys_get_opportunities==. 

gen bl_T_husbands_more=(bl_T_c35_husband_more_educated>=4)
replace bl_T_husbands_more=. if bl_T_c35_husband_more_educated==. 

gen bl_T_mothers_better_ed=(bl_T_c36_women_better_educator<=2)
replace bl_T_mothers_better_ed=. if bl_T_c36_women_better_educator==. 

gen bl_T_more_imp_boy_school=(bl_T_c37_important_boy_school>=4)
replace bl_T_more_imp_boy_school=. if bl_T_c37_important_boy_school==. 

gen bl_T_women_marry=(bl_T_c38_women_marry<=2)
replace bl_T_women_marry=. if bl_T_c38_women_marry==. 

local bl_gender_vars bl_T_women_marry bl_T_more_imp_boy_school bl_T_mothers_better_ed bl_T_husbands_more bl_T_boys_get_opp

swindex `bl_gender_vars' , gen(bl_gender_eq_swindex) 
 

 
**BL opinions on teacher effort 
***little variation: bl_T_c45_create_their_lesson
sum   bl_T_should_follow_crclm

gen bl_T_tries_hard= (bl_T_c47_tries_hard>=4)
replace bl_T_tries_hard=. if bl_T_c47_tries_hard==. 

 /*Not finished cleaning these bl_T_c48_student_work_hard bl_T_c49_difficult_teaching bl_T_c50_teachers_blamed bl_T_c51_motivated_class bl_T_c52_effective_math_teacher bl_T_c53_strict_teacher bl_T_c54_absent_occasionally bl_T_d01_appreciated bl_T_feel_valued bl_T_d02_headmast_helped bl_T_head_helped bl_T_d03_confident_to_teach bl_T_feel_confident bl_T_d04_my_fault_if_fail bl_T_my_fault bl_T_d05_have_materials bl_T_have_materials bl_T_d06_encourage_development bl_T_someone_encourages bl_T_d07_opinions_seem_count bl_T_opinion_counted  */
 
*Time use: few have other jobs 
gen bl_commuting_min = bl_T_e01_spend_commuting_hours*60 + bl_T_e01_spend_commuting_mins

gen bl_grading_home_min= bl_T_e03_home_grading_hours*60 + bl_T_e03_home_grading_mins
gen bl_grading_school_min= bl_T_e03_school_grading_hours*60 + bl_T_e03_school_grading_mins
gen bl_grading_min_total=bl_grading_home_min+bl_grading_school_min 
 
gen bl_prep_home_min = bl_T_e02_home_preparation_hours*60 + bl_T_e02_home_preparation_mins
gen bl_prep_school_min = bl_T_e02_preparation_hours*60 + bl_T_e02_school_preparation_mins
gen bl_prep_min_total=bl_prep_home_min+bl_prep_school_min 

 
gen bl_T_behavior=(bl_T_g01_behavior>=3)
replace bl_T_behavior=. if bl_T_g01_behavior==. 

gen bl_T_select_assessment =(bl_T_g03_evaluation>=3 )
replace bl_T_select_assessment=. if bl_T_g03_evaluation==. 


***************DEFINE ALL OF THESE LOCALS 
local demo_vars  years_this_school years_experience educ_masters_higher educ_bach_lower age male 

**BL knowledge of student variable (and opinions)
local bl_t_student_ability bl_T_c39_pass_percent_class9 bl_T_c40_simple_sentence bl_T_c41_substraction bl_T_c42_pass_percent_10board bl_T_c43_pass_percent_12board bl_T_c44_percent_complet_degree

local bl_t_opinion_vars bl_T_should_follow_crclm bl_T_tries_hard

local bl_time_use_vars bl_commuting_min bl_grading_home_min bl_grading_school_min bl_grading_min_total bl_prep_home_min bl_prep_school_min bl_prep_min_total


*Autonomy 
local bl_autonomy_vars bl_T_activity_selection bl_T_behavior bl_T_modify_timetable bl_T_select_assessment bl_T_fee_pressure bl_T_autonomy_swindex

*****local of baseline non-demographic variables 
local bl_nondemo_vars   bl_T_c45_create_their_lesson bl_T_c46_follow_govt_circular   bl_T_c48_student_work_hard bl_T_c49_difficult_teaching bl_T_c50_teachers_blamed bl_T_c51_motivated_class bl_T_c52_effective_math_teacher bl_T_c53_strict_teacher bl_T_c54_absent_occasionally bl_T_d01_appreciated bl_T_feel_valued bl_T_d02_headmast_helped bl_T_head_helped bl_T_d03_confident_to_teach bl_T_feel_confident bl_T_d04_my_fault_if_fail bl_T_my_fault bl_T_d05_have_materials bl_T_have_materials bl_T_d06_encourage_development bl_T_someone_encourages bl_T_d07_opinions_seem_count bl_T_opinion_counted 

local bl_nondemo_vars2  bl_gender_eq_swindex `bl_t_student_ability' `bl_t_opinion_vars' `bl_time_use_vars'  `bl_autonomy_vars'

***Local of student variables
local bl_student_test_vars bl_Eg_irt_wgt_std  bl_Ma_irt_wgt_std  bl_Od_irt_wgt_std  
local el_student_test_vars el_Eg_irt_wgt_std  el_Ma_irt_wgt_std  el_Od_irt_wgt_std el_Sc_irt_wgt_std





***Monitoring Visits
gen num_classes=mv_T_d05_avg_classes

gen teach_extra_classes=. 
replace teach_extra_classes=1 if mv_T_d16_extra_classes<=2
replace teach_extra_classes=0 if mv_T_d16_extra_classes==4

gen know_kids_behind = (mv_T_d20_aware_of_children>=4)
replace know_kids_behind=. if mv_T_d20_aware_of_children==.

gen mv_total_kids= mv_cl_b05_pupil_present_boy + mv_cl_b05_pupil_present_girls

***Imputing zero for some questions; should check this 
foreach var of varlist mv_cl_ask_question_student mv_cl_c08_ask_question_class mv_cl_c09_ask_indvidual_student mv_cl_c10_neutral_way mv_cl_c11_supportive_way mv_cl_answer_supportive mv_cl_c12_disrespectful mv_cl_student_express_idea{ 
replace `var'=0 if mv_cl_c08_ask_question_class==. & mv_cl_b10_teacher_absent==1
replace `var'=0 if mv_cl_c08_ask_question_class==. & mv_cl_b10_teacher_absent==1
}

****************Label Variables***************
***Demographics
label var educ_voc_lower "Education: Vocation or Lower"
label var educ_bach "Education: Bachelors"
label var educ_masters_higher "Education: Masters or Higher"
label var educ_bach_lower "Education: Bachlors or Lower"
label var years_this_school "Years at Current School"
label var years_experience "Years Total Experience"

***Competency 
***Minimum knowledge in math is scoring an 80% 
label var el_T_Cmp_Ma_pct_scored "Percent Scored on Overall Math Test"
label var el_T_Cmp_Ma_primary_pct_scored "Percent Scored on Lower-Primary Math Questions"
label var el_T_Cmp_Ma_primary_knowledge "Minimum Knowledge on Overall Math Test"
label var el_T_Cmp_Ma_prm_kldg_lower "Minimum Knowledge on Lower Primary Math Questions"
label var el_T_Cmp_Ma_only_irt_wgt_std "IRT Math Test, Math teachers only"
label var el_T_Cmp_Ma_irt_wgt_std "IRT Math Test, all teachers"


label var el_T_Cmp_Eg_pct_scored "Percent Scored on Overall English Test"
label var el_T_Cmp_Eg_total_score_part1 "Percent Scored on Part 1 of English Test"
label var el_T_Cmp_Eg_primary_knowledge "Minimum Knowledge on Overall English Test"
label var el_T_Cmp_Eg_only_irt_wgt_std "Std English Test, English teachers only"
label var el_T_Cmp_Eg_irt_wgt_std "Std English Test, all teachers"

***Student test scores 
label var bl_Eg_irt_wgt_std "Mean Student English Score (BL)"
label var el_Eg_irt_wgt_std "Mean Student English Score (EL)"
label var bl_Ma_irt_wgt_std "Mean Student Math Score (BL)"
label var el_Ma_irt_wgt_std "Mean Student Math Score (EL)"
label var bl_Od_irt_wgt_std "Mean Student Odia Score (BL)"
label var el_Od_irt_wgt_std "Mean Student Odia Score (EL)"
label var el_Sc_irt_wgt_std "Mean Student Science Score (Sc)"

***MV Variables
label var know_kids_behind "T Self-Reports Knows Which Children Behind (MV)"
label var teach_extra_classes "T Teaches Extra Classes (MV)"
label var num_classes "Num Classes Taught (MV)"
*label var mv_T_syllabus_behind "Behind the Syllabus (MV)"
 
 

***EL Variables 
label var el_T_Cmp_subject_teach_Ma "Math Teacher"
label var el_T_Cmp_subject_teach_Eg "English Teacher"
 
 


***Create school-level averages:  
bys school_id: gen obs=_n  //When obs=1, one observation per school 
bys school_id: egen temp_eng= mean(el_T_Cmp_Eg_pct_scored) if el_T_Cmp_subject_teach_Eg==1
bys school_id: egen school_eng_t_pct=max(temp_eng)
drop temp_eng 

label var school_eng_t_pct "English T Competency"
bys school_id: egen temp_math= mean(el_T_Cmp_Ma_pct_scored) if el_T_Cmp_subject_teach_Ma==1
bys school_id: egen school_ma_t_pct=max(temp_math) 
drop temp_math 
label var school_ma_t_pct "Math T Competency"
bys school_id: egen school_male_pct=mean(male)
label var school_male_pct "Percent Teachers Male"

bys school_id: egen school_years_avg=mean(years_experience)
label var school_years_avg "Avg Years Exp of Teachers"


 
